package Clain;

// 抽象处理器
public abstract class AbstractSafetyHandler implements SafetyHandler {
    private SafetyHandler nextHandler;

    @Override
    public void setNextHandler(SafetyHandler next) {
        this.nextHandler = next;
    }


    @Override
    public void handle(SafetyEvent event) {
        if (canHandle(event)) {
            process(event);
        } else if (nextHandler != null) {
            nextHandler.handle(event);
        } else {
            System.out.println("No handler available for event: " + event.getType());
        }
    }

    protected abstract boolean canHandle(SafetyEvent event);
    protected abstract void process(SafetyEvent event);
}
